/**
* Created by GoLand.
* User: link1st
* Date: 2019-07-25
* Time: 14:18
 */

package redislib

import (
	"context"
	"duoke/utils/yaml"
	"fmt"
	"github.com/go-redis/redis/v8"
)

var (
	client *redis.Client
)
var Redis *redis.Client

func Init() {
	config := yaml.GetConfig()
	client = redis.NewClient(&redis.Options{
		Addr:         config.Redis.Host + ":" + config.Redis.Port,
		Password:     config.Redis.Password,
		DB:           config.Redis.Db,
		PoolSize:     30,
		MinIdleConns: 30,
	})
	Redis = client
	ping := client.Ping(context.Background())
	if ping.Err() != nil {
		fmt.Println("[redis][info]:" + ping.Err().Error())
		return
	}
	// Output: PONG <nil>
}

func GetClient() (c *redis.Client) {

	return client
}
